﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using Library.Common;
using Library.Bll;
namespace HanhuaMicroCredit.BLL
{
    public class menuConfig
    {
        public menuConfig()
        {
        }
        public string _tname { get; set; }
        public int? _dtnum { get; set; }
        public int _id { get; set; }
        public int _pid { get; set; }
        public Dictionary<string, object> _d { get; set; }
        private Database _datebase {
            get {
                if (!_dtnum.HasValue)
                    _dtnum = 0;
                return (Database)_dtnum.Value;
            }
        }
        private string _conditions {
            get {
                return string.Format("id = {0}", _id);
            }
        }
        public static menuConfig Instance {
            get {
                return new menuConfig();
            }
        }
        public int A {
            get { return _Add(); }
        }
        public int U
        {
            get { return _Update(); }
        }
        public int D
        {
            get { return _Delete(); }
        }
        public int O
        {
            get { return _Order(); }
        }
        public Dictionary<string, object> G
        {
            get { return _GetModel(); }
        }
        public List<Dictionary<string, object>> S
        {
            get { return _Show(); }
        }
        //
        private int _Add()
        {
            return CommonBLL.Add(_datebase,_tname,_d);
        }
        private int _Update()
        {
            return CommonBLL.Update(_datebase,_tname, _d, _conditions);
        }
        private int _Delete()
        {
            return CommonBLL.Delete(_datebase, _tname, _conditions);
        }
        private int _Order()
        {
            return 1;
        }
        private Dictionary<string, object> _GetModel()
        {
            return CommonBLL.GetModel(_datebase, _tname, "*", _conditions);
        }
        private List<Dictionary<string, object>> _Show()
        {
            return CommonBLL.GetList(_datebase, _tname, "*", "[order]", string.Format("isvalid = 1 and parid={0}", _pid));
        }
    }
}
